<template>
     <div>
        <el-row :gutter="20" style="margin:10px;">
             <el-col :span="3" :offset="14">
              <el-input :value="plant" @change="plantChange"/>
            </el-col>
            <el-col :span="3">
               <el-select v-model="value" placeholder="请选择" @change="getData(value)">
                <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value">
                </el-option>
                </el-select>
            </el-col>
            <el-col :span="2">
                <el-button @click="goDataStatistics">数据分析</el-button>
            </el-col>
        </el-row>
        <ve-line :data="chartData" height="450px"></ve-line>
    </div>
</template>
<script>
import VeLine from 'v-charts/lib/line.common'
import {RTA} from '../../api/api'
// import { setInterval } from 'timers';
export default {
    data(){
        return{
            Id:this.$route.params["id"]==':id'?1:this.$route.params["id"],
            chartData:{},
            options: [{
                value: '1',
                label: '车间1'
                }, {
                value: '2',
                label: '车间2'
                }, {
                value: '3',
                label: '车间3'
                }],
            value: '1',
            plant:''
        }
    },
    created(){
        this.plant = `厂房${this.Id}`;
        this.getData(1);
    },
    components: { VeLine },
    methods:{
        getData(v){
            RTA({plant:this.Id,workshop:v}).then(res=>{
                let arr= [];
                let workshop = null;
                res.forEach((item,index) => {
                    if(workshop != item.workshop)
                    workshop = item.workshop;
                    let obj = {};
                    obj.冷气量 = item.cold;
                    obj.暖气量 = item.warm;
                    item.air_time = item.air_time.replace('T',' ');
                    let end = item.air_time.indexOf('.');
                    item.air_time = item.air_time.substring(0,end);
                    obj.时间 = item.air_time; 
                    arr.push(obj);
                });
                this.chartData = {
                    columns: ['时间', '冷气量','暖气量'],
                    rows: arr
                }; 
            });
        },
        plantChange(e){
            let a =  e.replace(/[^0-9]/ig,"");
            this.Id = a;
            this.getData(this.value);
        },
        goDataStatistics(){
            this.$router.push({path:'/statistics',query:{plant:this.Id,workshop:this.value}});
        }
    }
}
</script>

<style lang="scss" scoped>

</style>

